<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="./css/reset.css">
    <link rel="stylesheet" href="./css/layui/css/layui.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_1438114_f9np9f8pq4a.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_1438137_sw0m3wtabn.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_1438155_a4gtgz85jo.css">
    <title>学生管理</title>
    <style>
        .heardFont {
            width: 98.5%;
            height: 8vh;
            background: #fff;
            font: 18px/8vh "simhei";
            color: #797979;
            padding-left: 1.5%;
            border-top: 1px solid#fafafa;
        }

        .heardFont strong {
            color: #ababab;
        }

        ol {
            width: 98.6%;
            height: 30vh;
            font: 15px/5vh "simhei";
            color: #606266;
            border: 10px solid #f2f2f2;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-around;
            align-content: space-around;
        }

        ol li {
            width: 23%;
            height: 7vh;
        }

        ol li:nth-of-type(8) {
            opacity: 0;
        }

        #long {
            width: 70%;
        }

        #long input {
            width: 20%
        }

        #sort {
            width: 25%;
            float: right;
        }

        #sort span {
            width: 30%;
            height: 7vh;
            font: 14px/7vh "simhei";
            float: right;
            border-radius: 6px;
            background: #429788;
            margin-top: 1vh;
            color: #fff;
            text-align: center;
        }

        ol li label {
            display: inline-block;
            width: 30%;
        }

        ol li input,
        ol li select {
            width: 60%;
            height: 7vh;
            border: 1px solid #dcdfe6;
            border-radius: 6px;
        }

        #content {
            width: 98.6%;
            border: 10px solid #f2f2f2;
            border-top: none;
        }

        #top {
            width: 100%;
            height: 10vh;
        }

        #top em,
        #top .right span {
            width: 9%;
            height: 7vh;
            font: 14px/7vh "simhei";
            margin-top: 1.5vh;
            color: #fff;
            background: #429788;
            text-align: center;
            border-radius: 6px;
        }

        #top em {
            float: left;
            margin-left: 1%;
        }

        #top .right {
            float: right;
            width: 27%;
            height: 7vh;
            display: flex;
            justify-content: space-around;
            margin-right: 1%;
        }

        #top .right span {
            width: 30%;
        }

        table {
            margin: 1vh;
            width: 98%;
            margin-left: 1%;
            font-size: 12px;
            border: 1px solid #ebeef5;
            border-collapse: collapse;
            color: #606266;
        }

        table th {
            border: 1px solid #ebeef5;
            height: 8vh;
        }

        table tr {
            height: 8vh;
        }

        table tr:hover {
            background: #f5f7fa;
        }

        table td {
            border: 2px solid #ebeef5;
            text-align: center;
        }

        td p {
            color: #fff;
            float: left;
            width: 40%;
            padding-top: 0.5vh;
            padding-bottom: 0.5vh;
            border-radius: 4px;
        }

        td p:nth-of-type(1) {
            background: #5eb13d;
            margin-left: 10%;
            margin-right: 5%;
        }

        td p:nth-of-type(2) {
            background: #e3a345;
        }

        #page {
            margin-top: 10px;
            margin-bottom: 10px;
            color: #666;
            display: block;
            text-align: center;
        }

        #page ul {
            height: 10vh;
            border: none;
            width: 60%;
            margin-left: 20%;
        }

        #page li {
            display: inline-block;
            width: 30px;
            height: 28px;
            border-radius: 50%;
            cursor: pointer;
            color: #666;
            font-size: 13px;
            line-height: 28px;
            background-color: #f9f9f9;
            border: 1px solid #dce0e0;
            text-align: center;
            margin: 0 4px;
            -webkit-appearance: none;
            -moz-appearance: none;
            appearance: none;
        }

        #page li:nth-child(8) {
            width: 100px;
        }

        #page .xl-nextPage,
        #page .xl-prevPage {
            width: 60px;
            color: #429788;
            border-radius: 0px;
            height: 28px;
        }

        #page li.xl-disabled {
            opacity: .5;
            cursor: no-drop;
        }

        #page li.xl-disabled:hover {
            background-color: #f9f9f9 !important;
            border: 1px solid #dce0e0 !important;
            color: #666 !important;
        }

        #page li.xl-active {
            background-color: #429788;
            border-color: #429788;
            color: #FFF
        }

        #page li:hover {
            background-color: #429788 !important;
            border-color: #429788;
            color: #FFF
        }

        #page li.xl-jumpText {
            background-color: rgba(0, 0, 0, 0);
            border-color: rgba(0, 0, 0, 0);
            opacity: 1;
        }

        #page li.xl-jumpText:hover {
            background-color: rgba(0, 0, 0, 0) !important;
            border-color: rgba(0, 0, 0, 0) !important;
        }

        #page li.xl-jumpButton {
            padding: 0 5px;
        }

        #xlJumpNum {
            width: 35px;
            margin: 0 3px;
        }

        input::-webkit-outer-spin-button,
        input::-webkit-inner-spin-button {
            -webkit-appearance: none !important;
        }

        input[type="number"] {
            -moz-appearance: textfield;
        }

        .aremind {
            width: 350px;
            height: 200px;
            background: rgb(32, 34, 42, 0.6);
            position: fixed;
            bottom: 10px;
            right: 10px;
            border-radius: 5px;
            color: #c1c1c1;
            overflow: hidden;
        }

        .topRemind {
            width: 96%;
            height: 30px;
            font: 15px/30px 'simhei0';
            margin-left: 2%;
            border-bottom: 1px solid white;

        }

        .botRemind {
            width: 96%;
            margin-left: 2%;
            height: 170px;
            position: relative;
            overflow: hidden;
        }

        .inRemind {
            width: 100%;
            position: absolute;
            top: 0;
            left: 0;
        }

        .inRemind ul {
            width: 100%;
            height: 17px;
            font: 15px/17px "simhei";
            cursor: pointer;
        }

        .inRemind ul:hover {
            color: white;
        }

        .topRemind i {
            float: right;
        }

        .botRemind ul li {
            float: left;

        }

        .inRemind ul li:nth-of-type(3) {
            margin-left: 10%;
            margin-right: 16%;
        }

        #form {
            position: relative;
            width: 80%;
            height: 7vh;
            margin-top: 1.5vh;
            margin-left: 2%;
        }

        #formSet {
            width: 40%;
            height: 100%;
            float: right;
            font-size: 16px;
            line-height:7vh;
            color: #fff;
            margin-right: 10px;
            text-align: center;
            border-radius: 4px;
            background: #429788;
            border: 1px solid #429788;
            overflow: hidden;
            cursor: pointer;
            position: relative;
            /* display: none; */
        }

        #form #file {
            width: 100%;
            height: 100%;
            background: red;
            border: 1px solid #429788;
            opacity: 0;
            cursor: pointer;
            position: absolute;
            left: 0px;
            top: 0px;

        }

        #sub {
            width: 40%;
            height: 100%;
            font-size: 16px;
            line-height: 40px;
            color: #fff;
            border-radius: 4px;
            background: #429788;
            border: 1px solid #429788;
            opacity: 1;
            cursor: pointer;
            position: absolute;
            left: 0;
            top: 0px;
        }
    </style>
</head>

<body>
    <div id="wrap">
        <div class="heardFont">
            <span>学生管理</span>
            <strong>/ 学生列表</strong>
        </div>
        <ol id="middle">
            <li>
                <lable>学生姓名</lable>
                <input type="text" placeholder="请输入学生姓名" id="stuName">
            </li>
            <li>
                <lable>员工姓名</lable>
                <input type="text" placeholder="请输入员工姓名" id="empName">
            </li>
            <li>
                <lable> 电 话 </lable>
                <input type="text" placeholder="请输入电话" id="telphone">
            </li>
            <li>
                <lable>身份证号</lable>
                <input type="text" placeholder="请输入身份证号" id="idCord">
            </li>
            <li>
                <lable> 微 信 号 </lable>
                <input type="text" placeholder="请输入微信号" id="weixin">
            </li>
            <li>
                <lable> Q Q 号 </lable>
                <input type="text" placeholder="请输入QQ号" id="qq">
            </li>
            <li>
                <lable> 状 态 </lable>
                <select id="state">
                </select>
            </li>
            <li>
                <!-- <lable> 状 态 </lable> -->
            </li>
            <li id="long">
                <lable>报名时间</lable>
                <input type="text" id="day" placeholder="开始日期" id="inTime">
                --
                <input type="text" id="day2" placeholder="截止日期" id="outTime">
            </li>
            <li id="sort">
                <span><i class="icon iconfont icon-sousuo"></i>搜索</span>
            </li>
        </ol>
        <div id="content">
            <div id="top">
                <em><i class="icon iconfont icon-icon-test"></i>添加</em>
                <div class="right">
                    <span><i class="icon iconfont icon-fenpei"></i>分配班级</span>
                    <form id="form" method="post" enctype="multipart/form-data">

                        <div id="formSet">
                            导入

                            <input type="file" name="file" id="file">
                        </div>
                        <input type="submit" value="提交" id="sub">
                    </form>
                    <span id="generate-excel"><i class="icon iconfont icon-daochu"></i>导出</span>
                </div>
            </div>
            <table id="test_table">
                <tr>
                    <th>
                        <input type="checkbox">
                    </th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>电话</th>
                    <th>毕业院校</th>
                    <th>专业</th>
                    <th>状态</th>
                    <th>紧急联系人</th>
                    <th>紧急联系人呢电话</th>
                    <th>操作</th>
                </tr>
            </table>
            <div class="page" id="page"></div>
        </div>
        <div class="aremind">
            <div class="topRemind">提醒事项 <i class="layui-icon layui-icon-spread-left"></i></div>
            <div class="botRemind">
                <div class="inRemind">
                </div>
            </div>
        </div>
    </div>
</body>
<script src="./js/jquery-3.4.1.js"></script>
<script src="./css/layui/layui.js"></script>
<script src="./js/xlPaging.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/jszip/3.1.5/jszip.min.js"></script>
<script src="./js/url.js"></script>
<script src="http://malsup.github.io/jquery.form.js"></script>
<script>
    var arr = [];
    $("#page").paging({
        nowPage: 1, // 当前页码
        pageNum: 10, // 总页码
        buttonNum: 1, //要展示的页码数量
        canJump: 1,// 是否能跳转。0=不显示（默认），1=显示
        showOne: 0,//只有一页时，是否显示。0=不显示,1=显示（默认）
        callback: function (num) { //回调函数
            localStorage.pageNum = num;
        }
    });
    $("#page ").on("click", " ul li", function () {
        pageNum = localStorage.pageNum;
        pageAjax(pageNum)
    })
    function pageAjax(page) {
        $.ajax({
            type: "post",
            url: SetUrl.studentUrl,
            dataType: "json",
            data: {
                "method": "search",
                'currentPage': page,
                'rows': '10'
            },
            success: function (data) {
                if (data.code == 200) {
                    $("#test_table").find('th').parent().siblings().remove()
                    console.log(data)
                    var olist = data.result.list;
                    for (var i = 0; i < olist.length; i++) {
                        var otr = $('<tr></tr>').attr('studentId', olist[i].studentId);
                        otr.appendTo($("#test_table"));
                        $('<td><input type="checkbox"></td>').appendTo(otr);
                        $('<td>' + olist[i].studentName + '</td>').appendTo(otr);
                        if (olist[i].studentSex == 1) {
                            var sex = '男'
                        } else {
                            var sex = '女'
                        }
                        $('<td>' + sex + '</td>').appendTo(otr);
                        $('<td>' + olist[i].age + '</td>').appendTo(otr);
                        $('<td>' + olist[i].telphone + '</td>').appendTo(otr);
                        $('<td>' + olist[i].schoolName + '</td>').appendTo(otr);
                        $('<td>' + olist[i].major + '</td>').appendTo(otr);
                        $('<td>' + olist[i].stateName + '</td>').appendTo(otr);
                        $('<td>' + olist[i].emergencyName + '</td>').appendTo(otr);
                        $('<td>' + olist[i].emergencyContact + '</td>').appendTo(otr);
                        $('<td><p class = "p1"><i class="icon iconfont icon-chakan"></i>查看</p><p class = "p2"><i class="icon iconfont icon-bianji"></i>编辑</p></td>').appendTo(otr);
                    }
                    $("#test_table").on('click', ".p1", function () {
                        localStorage.setId = $(this).parent().parent().attr("studentId");
                        window.location = "BX_LookStudent.html";
                    })
                    $("#test_table").on('click', ".p2", function () {
                        localStorage.setId = $(this).parent().parent().attr("studentId");
                        window.location = "BX_ EditStudentInfo.html";
                    })
                }
            },
            error: function (xhr, error) {
                console.log(error)
            }
        })
    }

    $(function () {
        $.ajax({
            url: SetUrl.remind.state,
            type: 'post',
            dataType: 'json',
            data: {
                "moduleId": 1,
                "remindState": 1
            },
            success: function (data) {
                console.log(data);
                var liM = data.result;
                for (var i = 0; i < liM.length; i++) {
                    var time = liM[i].remindTime;
                    var newTime = new Date(time);
                    var iY = newTime.getFullYear();
                    var iMoth = newTime.getMonth() + 1;
                    var iDay = newTime.getDate();
                    var iH = newTime.getHours();
                    var iM = newTime.getMinutes();
                    var iS = newTime.getSeconds();
                    var li = $("<ul>").addClass("clear").appendTo(".inRemind");
                    $("<li>").html(".").appendTo(li);
                    $("<li>").html(" ").appendTo(li);
                    $("<li>").html(liM[i].remindContent).appendTo(li);
                    $("<span>").html(iY + "-" + iMoth + "-" + iDay + " " + iH + ":" + iM + ":" + iS).appendTo(li);

                }
                //右下角提醒
                var num = 0;
                var aHeight = parseFloat($('.inRemind').height());
                console.log(aHeight);
                var iTimer = setInterval(function () {
                    num -= 5;
                    if ((aHeight + num) <= 170) {
                        num = 0
                    }
                    $('.inRemind').css({
                        top: num
                    })
                }, 200)
                var onOff = true;
                $('.aremind').find('i').click(function () {
                    if (onOff) {
                        $('.botRemind').css({
                            display: 'none'
                        }),
                            $('.aremind').css({
                                height: '40px'
                            })
                        onOff = false;
                    } else {
                        $('.botRemind').css({
                            display: 'block'
                        })
                        $('.aremind').css({
                            height: '200px'
                        })
                        onOff = true;
                    }
                })
            },
            error: function (xhr, errorInfo) {
                console.log('-------');
            }
        });
    })
    $("#formSet").on("click", function () {
        $("#sub").css("display", "block");

    });
    console.log(localStorage.con)
    //导入
    $("#sub").on("click", function () {
        $("#form").on("submit", function () {
            $(this).ajaxSubmit({
                url: SetUrl.daoru,
                type: "post",
                dataType: "json",
                enctype: "multipart/form-data",
                success: function (data) {
                    console.log("1")
                    localStorage.con = "1"
                },
                error: function (xhr, err) {
                    console.log("2")
                }
            });
            $(this).resetForm(); // 提交后重置表单
            return false; // 阻止表单自动提交事件
        });
    })
    // 导出的方法

    function tableToExcel(arr) {
        //要导出的json数据
        var jsonData = arr;
        //列标题，逗号隔开，每一个逗号就是隔开一个单元格
        var str = `姓名,电话,邮箱\n`;
        //增加\t为了不让表格显示科学计数法或者其他格式
        for (var i = 0; i < jsonData.length; i++) {
            for (var item in jsonData[i]) {
                str += `${jsonData[i][item] + '\t'},`;
            }
            str += '\n';
        }
        //encodeURIComponent解决中文乱码
        var uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
        //通过创建a标签实现
        var link = document.createElement("a");
        link.href = uri;
        //对下载的文件命名
        link.download = "json数据表.csv";
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    }


    // 日历
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#day'
        });
    });
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#day2'
        });
    });
    // 分页器
    // $("#page").paging({
    //     nowPage: 1, // 当前页码
    //     pageNum: 10, // 总页码
    //     buttonNum: 1, //要展示的页码数量
    //     canJump: 1,// 是否能跳转。0=不显示（默认），1=显示
    //     showOne: 0,//只有一页时，是否显示。0=不显示,1=显示（默认）
    //     callback: function (num) { //回调函数
    //         console.log(num);
    //     }
    // });
    // 全选
    $('th input').click(function () {
        console.log($(this).prop("checked"))
        if ($(this).prop("checked") == true) {
            $(' td input:checkbox').each(function (i, v) {

                if ($(v).prop("checked") == 'checked') {
                    console.log("true之后遍历之后的true进来")
                    $(this).attr('checked', false);

                } else {
                    console.log('true之后的false进来')
                    $('tr td input').prop("checked", true)
                }
            });

        } else if ($(this).prop("checked") == false) {
            console.log("腐恶")
            $(' td input:checkbox').each(function (i, v) {

                if ($(v).prop("checked") == true) {

                    console.log("false之后true")
                    $(this).prop('checked', false);

                } else {

                    console.log('false之后false')
                    $(this).attr("checked", false)
                }
            });
        }
    })
    // 单个点击全部后 顶部选中

    $('tr td input').click(function () {
        var chknum = $("td :checkbox").length;//选项总个数
        var chk = 0;
        $("td :checkbox").each(function () {
            if ($(this).prop("checked") == true) {
                chk++;
            }
        });
        if (chknum == chk) {//全选
            $("th  input").prop("checked", true);
        } else {//不全选
            $("th  input").prop("checked", false);
        }
    })
    //链接跳转
    $('#top').find('em').click(function () {
        location.href = "Bx_studentMasage.html";
    })
    $('#test_table td p:eq(0)').each(function (i, v) {
        $(v).on('click', function () {
            location.href = "BX_LookStudent.html";
        })
    })

    $('#test_table td p:eq(1)').click(function () {
        location.href = "BX_writeStudent.html";
    })

    $(function () {
        $.ajax({
            type: "post",
            url: SetUrl.studentUrl,
            dataType: "json",
            data: {
                "method": "search",
                'currentPage': '1',
                'rows': '10'
            },
            success: function (data) {
                if (data.code == 200) {
                    console.log(data)
                    var olist = data.result.list;
                    arr =data.result.list;
                    for (var i = 0; i < olist.length; i++) {
                        var otr = $('<tr></tr>').attr('studentId', olist[i].studentId);
                        otr.appendTo($("#test_table"));
                        $('<td><input type="checkbox"></td>').appendTo(otr);
                        $('<td>' + olist[i].studentName + '</td>').appendTo(otr);
                        if (olist[i].studentSex == 1) {
                            var sex = '男'
                        } else {
                            var sex = '女'
                        }
                        $('<td>' + sex + '</td>').appendTo(otr);
                        $('<td>' + olist[i].age + '</td>').appendTo(otr);
                        $('<td>' + olist[i].telphone + '</td>').appendTo(otr);
                        $('<td>' + olist[i].schoolName + '</td>').appendTo(otr);
                        $('<td>' + olist[i].major + '</td>').appendTo(otr);
                        $('<td>' + olist[i].stateName + '</td>').appendTo(otr);
                        $('<td>' + olist[i].emergencyName + '</td>').appendTo(otr);
                        $('<td>' + olist[i].emergencyContact + '</td>').appendTo(otr);
                        $('<td><p class = "p1"><i class="icon iconfont icon-chakan"></i>查看</p><p class = "p2"><i class="icon iconfont icon-bianji"></i>编辑</p></td>').appendTo(otr);
                    }
                    $("#test_table").on('click', ".p1", function () {
                        localStorage.setId = $(this).parent().parent().attr("studentId");
                        window.location = "BX_LookStudent.html";
                    })
                    $("#test_table").on('click', ".p2", function () {
                        localStorage.setId = $(this).parent().parent().attr("studentId");
                        window.location = "BX_ EditStudentInfo.html";
                    })
                }
                $("#generate-excel").click(function () {
                    tableToExcel(arr)
                })
            },
            error: function (xhr, error) {
                console.log(error)
            }
        })
    })

    //下拉AJAX
    $("#state").on("click", function () {
        $.ajax({
            type: "post",
            url: SetUrl.studentUrl,
            dataType: "json",
            data: {
                "method": "states",
                'jobId': 5
            },
            success: function (data) {
                console.log(data)
                if (data.code == 200) {
                    var list = data.result;
                    for (var i = 0; i < list.length; i++) {
                        $("<option value=''>" + list[i].stateName + "</option>").appendTo($('#state'));
                    }
                }
            },
            error: function (xhr, error) {
                console.log(error)
            }
        })
    })

    //搜索AJAX
    $("#sort").on("click", function () {
        $.ajax({
            type: "post",
            url: SetUrl.studentUrl,
            dataType: "json",
            data: {
                "method": "search",
                'currentPage': '1',
                'rows': '10',
                'sName': $('#stuName').val(),
                'empName': $('#empName').val(),
                'telphone': $('#telphone').val(),
                'idCord': $('#idCord').val(),
                'weixin': $('#weixin').val(),
                'qq': $('#qq').val(),
                'stateId': $('#state').val(),
                'inTime': $('#inTime').val(),
                'outTime': $('#outTime').val(),
            },
            success: function (data) {
                if (data.code == 200) {
                    console.log(data)
                    $('th').parent().siblings().remove()
                    var olist = data.result.list;
                    for (var i = 0; i < olist.length; i++) {
                        var otr = $('<tr></tr>').attr('studentId', olist[i].studentId);;
                        otr.appendTo($("#test_table"));
                        $('<td><input type="checkbox"></td>').appendTo(otr);
                        $('<td>' + olist[i].studentName + '</td>').appendTo(otr);
                        if (olist[i].studentSex == 1) {
                            var sex = '男'
                        } else {
                            var sex = '女'
                        }
                        $('<td>' + sex + '</td>').appendTo(otr);
                        $('<td>' + olist[i].age + '</td>').appendTo(otr);
                        $('<td>' + olist[i].telphone + '</td>').appendTo(otr);
                        $('<td>' + olist[i].schoolName + '</td>').appendTo(otr);
                        $('<td>' + olist[i].major + '</td>').appendTo(otr);
                        $('<td>' + olist[i].stateName + '</td>').appendTo(otr);
                        $('<td>' + olist[i].emergencyName + '</td>').appendTo(otr);
                        $('<td>' + olist[i].emergencyContact + '</td>').appendTo(otr);
                        $('<td><p class = "p1"><i class="icon iconfont icon-chakan"></i>查看</p><p class = "p2"><i class="icon iconfont icon-bianji"></i>编辑</p></td>').appendTo(otr);
                    }
                    $("#test_table").on('click', ".p1", function () {
                        localStorage.setId = $(this).parent().parent().attr("studentId");
                        window.location.herf = "BX_LookStudent.html";
                    })
                    $("#test_table").on('click', ".p2", function () {
                        localStorage.setId = $(this).parent().parent().attr("studentId");
                        window.location.herf = "BX_ EditStudentInfo.html";
                    })
                }
            },
            error: function (xhr, error) {
                console.log(error)
            }
        })
    })

</script>

</html>